package com.yc.mvc.web;

import com.yc.mvc.web.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

// Controller: 该类方法的返回值默认是页面跳转, 必须返回String
@Controller
public class DemoController {

    @RequestMapping("ttoIndexJsp")
    public String ttoIndexJsp(){
        return "index.jsp";
    }
    @RequestMapping("ggoIndexJsp")
    public String ggoIndexJsp(){
        return "redirect:index.jsp";
    }

    @ResponseBody
    @RequestMapping("Myinfo")
    public User myinfo(){
        User user = new User();
        user.setName("ly");
        user.setPwd("123");
        user.setAge(100);
        return user;
    }

    @GetMapping("login")
    @ResponseBody
    public String login(String name, String pwd){
        return name + " : " + pwd;
    }

    @GetMapping("reg")
    @ResponseBody
    public String reg(String name, String pwd, int age, Boolean man){
        return name + " : " + pwd + " : " + age + " : " + man;
    }

    @RequestMapping("reg1")
    @ResponseBody
    // 默认表单方式接受参数
    public User reg1(User user){
        return user;
    }

    @RequestMapping("reg2")
    @ResponseBody
    // @RequestBody 表示请求中的数据是  JSON 格式的数据
    public User reg2(@RequestBody User user){
        return user;
    }

}
